package com.dabai.iot.core.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dabai.common.mybatis.core.page.PageQuery;
import com.dabai.common.mybatis.core.page.TableDataInfo;
import com.dabai.common.web.core.BaseController;
import com.dabai.iot.core.dto.DeviceLogQuery;
import com.dabai.iot.core.service.IDeviceLogService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * 设备日志 控制器
 *
 * @author kev1n
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/device/log")
public class DeviceLogController extends BaseController {

    private final IDeviceLogService deviceLogService;

    /**
     * 设备日志分页
     */
    @GetMapping("/page")
    @Operation(summary = "设备日志分页", description = "传入对应查询参数")
    public TableDataInfo<Map<String, Object>> page(PageQuery pageQuery, @Validated DeviceLogQuery deviceLogQuery) {
        StopWatch stopWatch = new StopWatch("getDeviceLogPageFromTD");
        stopWatch.start();

        IPage<Map<String, Object>> pages = deviceLogService.getDeviceLogPageFromTD(pageQuery.build(), deviceLogQuery);

        stopWatch.stop();
        log.info("StopWatch==> [{}]: running time = {} ms", stopWatch.getId(), stopWatch.getTotalTimeMillis());
        return TableDataInfo.build(pages);
    }

}
